<?php

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;

class RoleSeed extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $role = Role::create(['name' => 'administrator']);

        $details = array(
            array('explain' => '修改权限', 'name' => 'update power'),
            array('explain' => '创建权限', 'name' => 'create power'),
            array('explain' => '查看权限', 'name' => 'watch power'),
            array('explain' => '删除权限', 'name' => 'delete power'),

            array('explain' => '创建用户', 'name' => 'create user'),
            array('explain' => '修改用户', 'name' => 'update user'),
            array('explain' => '查看用户', 'name' => 'watch user'),
            array('explain' => '删除用户', 'name' => 'delete user'),
            array('explain' => '修改密码', 'name' => 'change_password'),

            array('explain' => '创建角色', 'name' => 'create roles'),
            array('explain' => '修改角色', 'name' => 'update roles'),
            array('explain' => '查看角色', 'name' => 'watch roles'),
            array('explain' => '删除角色', 'name' => 'delete roles'),
        );

        foreach ($details as $key => $value) {
            $role->givePermissionTo(['name' => $value['name']]); 
        }

        // $role->givePermissionTo('users_manage'); //绑定一个权限


    }
}
